import { GET, POST } from "./config";
import axios from "axios";

const instance = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, //发送请求时，会在url前拼接baseUrl
  // baseURL:"http://192.168.180.66:9998/",//发送请求时，会在url前拼接baseUrl

  timeout: 10000,
});

//封装GET POST
export function request(method, url, params) {
  switch (method) {
    case GET:
      return get(url, params);
    case POST:
      return post(url, params);
  }
}

function get(url, params) {
  return instance({
    url: url,
    method: "get",
    params: params,
  });
}

function post(url, params) {
  return instance({
    url: url,
    method: "post",
    data: params,
    headers: {
      "Content-Type": "application/json ",
    },
  });
}
